package com.javasm.crm.controller.gift;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javasm.crm.common.http.AxiosResult;
import com.javasm.crm.controller.base.BaseController;
import com.javasm.crm.domin.criteria.GiftInfoCriteria;
import com.javasm.crm.domin.entity.gift.*;
import com.javasm.crm.mapper.giftmapper.GiftInfoMapper;
import com.javasm.crm.service.giftservice.GiftInfoService;
import com.javasm.crm.utils.page.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author whl
 * @since 2021-07-12
 */
@RestController
@RequestMapping("GiftInfo")
@Api(value = "GiftController", description = "赠品管理")

public class GiftInfoController {

	@Autowired
	GiftInfoService giftInfoService;

	@Autowired
	GiftInfoMapper giftInfoMapper;

	@GetMapping("getGift")
	@ApiOperation(value = "条件查询", notes = "条件查询")
	public AxiosResult<PageResult<GiftVo>> getGift(GiftInfoCriteria giftInfoCriteria) {
		PageResult<GiftVo> giftVoPageResult = giftInfoService.searchPageByCriteria(giftInfoCriteria);
		return AxiosResult.success(giftVoPageResult);
	}

	@GetMapping("getColor")
	@ApiOperation(value = "查询颜色", notes = "查询颜色")
	public AxiosResult<List<GiftColor>> getColor() {
		List<GiftColor> color = giftInfoService.findColor();
		return AxiosResult.success(color);
	}

	@GetMapping("getType")
	@ApiOperation(value = "查询类型", notes = "查询类型")
	public AxiosResult<List<GiftType>> getType() {
		List<GiftType> type = giftInfoService.findType();
		return AxiosResult.success(type);
	}

	@GetMapping("getBrand")
	@ApiOperation(value = "查询颜色", notes = "查询颜色")
	public AxiosResult<List<GiftBrand>> getBrand() {
		List<GiftBrand> brand = giftInfoService.findBrand();
		return AxiosResult.success(brand);
	}

	@PostMapping("addGift")
	@ApiOperation(value = "添加赠品", notes = "添加赠品")
	public AxiosResult<Integer> addGift(@RequestBody(required = false) GiftInfo giftInfo) {
		int save = giftInfoService.addGift(giftInfo);
		return BaseController.toAxiosResult(save);
	}

	@PutMapping("editGift")
	@ApiOperation(value = "修改赠品", notes = "修改赠品")
	public AxiosResult<Integer> editGift(@RequestBody(required = false) GiftInfo giftInfo) {
		int save = giftInfoService.editGift(giftInfo);
		return BaseController.toAxiosResult(save);
	}

	@DeleteMapping("deleteById/{giftId}")
	@ApiOperation(value = "删除用户", notes = "删除用户")
	public AxiosResult<Integer> deleteUser(@PathVariable Integer giftId) {
		int deleteById = giftInfoService.deleteById(giftId);
		return BaseController.toAxiosResult(deleteById);
	}



}
